package us.mooresr.aircraftscheduling.server.handler;


import us.mooresr.aircraftscheduling.server.DAO;
import us.mooresr.aircraftscheduling.server.MailNotifier;
import us.mooresr.aircraftscheduling.shared.action.DeleteReservationAction;
import us.mooresr.aircraftscheduling.shared.action.DeleteReservationResult;
import us.mooresr.aircraftscheduling.shared.model.Reservation;

import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

public class DeleteReservationHandler 
	implements ActionHandler<DeleteReservationAction, DeleteReservationResult> {

	@Override
	public DeleteReservationResult execute(DeleteReservationAction arg0,
			ExecutionContext arg1) throws ActionException {
		DAO dao = new DAO();
		
		// Notify before delete, because notify needs some details that will be gone once we do the delete
		
		MailNotifier m = MailNotifier.getInstance();
		m.sendDeletedReservationNotifications(arg0.getReservation());
		
		
		dao.ofy().delete(Reservation.class,arg0.getReservation().getReservationId());
		

		
		return new DeleteReservationResult(arg0.getReservation());
	}

	@Override
	public Class<DeleteReservationAction> getActionType() {
		return DeleteReservationAction.class;
	}

	@Override
	public void undo(DeleteReservationAction arg0,
			DeleteReservationResult arg1, ExecutionContext arg2)
			throws ActionException {

		
	}

}
